Skip to content

feat(agents): Agent 插件上报并修改模型与供应商,资源库读取支持筛选与排序 - #248

Merged
xiaoyumuxi merged 2 commits into
mainfrom
feat/agent-providers-and-library-filter
Dec 2, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
feat/agent-providers-and-library-filter

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联

改动

一、API-45:Agent 插件上报并修改模型与供应商(agents 能力 0 内的补充,不升版本)

  • 清单 agents[].configuration.providers:read、可选的 edit 与 operations(addProvider、updateProvider、removeProvider、setProviderEnabled、setModel、setProvider、setProfile)。必须同时声明 files;edit 和 operations 同有同无;权限沿用 agents.configuration。
  • 宿主命令 agentProviders.read({agent?}):每个 Agent 一项,含 CLI 版本、当前模型及来源层(用户配置 / 配置档 / 默认值 / 环境变量名)、当前供应商、配置里的供应商(ID、显示名、接口地址、协议、密钥环境变量名、请求头名、是否启用、是否内置)、配置档、账号标签、来源文件路径。未授权的 Agent 只列出,不调用插件。
  • 宿主命令 agentProviders.apply({agent, change},只接受用户发起):在暂存副本上调用插件的 edit,回读确认修改生效,检查文件没被别人改过后替换。
  • 隐私边界由 Core 执行并有测试:密钥、请求头、查询参数只有名字,没有能放值的字段;baseUrl 只能是 http/https、必须有 host,不能带用户名、密码、查询参数、片段;条目数与长度都有上限。契约写明插件不得读凭据文件和钥匙串。
  • 设置里环境块中的端点变量由插件解析成该供应商的 baseUrl,走同一条地址校验;块里其他变量只给名字(environmentNames)。Core 不含任何具体变量名或 Agent 名。
  • 错误码 agentProviders.* 共 16 个,一码一义(见契约 README)。
  • 日志事件 agent.providers.read_finished / read_failed / change_applied / change_failed,只记操作、数量、耗时和错误码。

二、agentLibrary.read 支持筛选与排序

  • 可选参数 query、agent + presence(present / missing)、sort(name / agentCount)。
  • 带参数时回答多一个 matches: {mcpServers, hooks, skills},只给键;library、skills、states、agents 仍然完整(save 是整体覆盖)。不带参数时回答与之前完全一致。
  • 新错误码 agentLibrary.invalidFilter。

三、顺带修复

  • Agent 日志里的耗时字段名不对,会被静默丢掉,统一为 duration_ms(live.rs、records.rs、library.rs)。

文档与契约

  • 契约 README、清单 schema、fixture(含 7 个非法清单用例)、reference/domains/agents.md、capabilities-and-versions.md、api-catalog.md 的 API-45 行、协议更新记录、四语 SDK README。
  • agentProviders.* 是宿主到 Core 的命令,providers.read / edit 是插件函数,都不是插件调用的宿主方法,所以方法表和“宿主方法(按 API 编号)”索引没有加行,与 feat(agents): 统计支持拆分维度、筛选,并给出每组速度中位数与首字平均耗时 #245 的处理一致。
  • SDK 没有类型变化(普通 JSON 函数),没有新增示例。

兼容

  • 旧 Core 遇到 providers 会把它当未知字段拒绝整个清单;遇到新的筛选参数以 agents.invalidPayload 拒绝。
  • 没有声明 providers 的插件不受影响。

验证(macOS,本机)

命令 结果
cargo fmt --check 通过
cargo test -p lithe-agent-runtime -p lithe-plugin-agents 54 + 20 通过
cargo test -p lithe-core -p lithe-diagnostics 通过
cargo clippy --workspace --all-targets --all-features -- -D warnings 通过
scripts/rust-core/verify-rust-core-comments.sh 通过
node shared/plugins/scripts/verify-docs.mjs 通过
node shared/plugins/scripts/sdk-e2e.mjs 通过

未执行:整个 workspace 的测试只跑了上面四个 crate;Windows 目标的 clippy 本机编不了 zstd-sys,看 CI。

@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review December 2, 2026 03:44
@xiaoyumuxi
xiaoyumuxi merged commit 32bd16c into main Dec 2, 2026
9 of 11 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Self::AddProvider { provider } | Self::UpdateProvider { provider } => snapshot
.find(&provider.id)
.is_some_and(|found| provider.is_in(found)),
Self::RemoveProvider { id } => snapshot.find(id).is_none(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Unchecked deletion of unrelated providers

When a plugin’s removal edit drops other providers too, shows_in still passes. edit_staged then replaces the real configuration and reports success.

Learn more

Core reads the agent’s provider configuration before calling its plugin, then asks the plugin to read the staged file after editing it. The removal check confirms the requested provider existed before the edit. The staged verification only confirms that it no longer appears. edit_staged installs the staged bytes once that check passes and the original file still matches.

Example: Configure alpha and gamma, then remove alpha. The synthetic backend’s wrong-edit mode replaces the staged configuration with an unrelated JSON object. Its reader still returns a valid snapshot containing the built-in provider and a default model. The removal check passes even though gamma is gone too.

Recommended fix: Verify the removal against the pre-edit snapshot as well as the staged snapshot. Require unrelated provider records to survive, allowing only explicitly supported changes to derived fields. Add a removal test using the wrong-edit mode and verify that the original file remains byte-for-byte unchanged.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +941 to +942
let snapshot = read_providers(link, agent, configuration, declared, &paths.files)?;
change.check_against(&snapshot)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Provider addition overwrites concurrent additions

If another writer adds the same provider before staging, check_against still approves the addition using the earlier snapshot. edit_staged copies the newer file, so its final byte check does not catch the stale approval.

Learn more

The provider command checks that an add uses a new ID before preparing the staged file. That check uses the plugin’s first read, which is not tied to any file revision. edit_staged captures its baseline later and detects only changes made after that capture. The synthetic provider editor assigns the requested provider by ID, relying on Core’s duplicate check to distinguish adds from updates.

Example: Start adding gateway. The initial read sees no such provider. The CLI saves its own gateway before Core copies the file. The edit replaces that entry in the copy, and the final byte check passes because the real file still contains the CLI’s version that Core copied.

Recommended fix: Check the operation against a read of the unmodified staged copy before invoking the editor, and verify it still resolves to the chosen target. Keep the existing comparison against the exact bytes staged so writes after that point still cause a refusal.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +263 to +268
let authority = rest.split('/').next().unwrap_or_default();
let host = authority.strip_prefix('[').map_or_else(
|| authority.split(':').next().unwrap_or_default(),
|v6| v6.split(']').next().unwrap_or_default(),
);
!authority.contains('@') && !host.is_empty()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Malformed provider URLs pass validation

When a user mistypes a port as 8O80, is_endpoint accepts it. Both the edit and its read-back use that check, so the unusable endpoint can be saved.

Learn more

The endpoint check is shared by provider input and snapshot validation. It finds the start of a host without parsing the URL, so a nonnumeric port or unmatched IPv6 bracket passes both paths.

Example: Add a provider at https://api.example.com:8O80/v1. A plugin that stores and reports the supplied endpoint lets the edit pass, instead of Core returning agentProviders.invalidEndpoint.

Recommended fix: Use the crate’s existing url dependency to validate the full host and port. Retain checks for whitespace, controls and disallowed URL components, including empty userinfo, and test malformed ports and IPv6 addresses for both input and read-back.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +1356 to +1361
query.as_deref().is_none_or(|query| {
candidate
.texts
.iter()
.any(|text| text.to_lowercase().contains(query))
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Library search misses final sigma

Searching for Σ misses ΦΩΣ because matching lowercases the query to σ but the item ends in ς.

Learn more

The library query contract specifies case-insensitive substring matching. Rust lowercases Greek capital sigma differently when it ends a word than when it appears alone, so lowercasing the entire strings independently can turn an exact substring into a mismatch.

Example: Save an MCP server named ΦΩΣ and search for Σ. The server name becomes φως, while the query becomes σ. The server is absent from the results.

Recommended fix: Use the same Unicode case-folding function for the query and candidate text, and cover final sigma with a library read test. Reuse the folding for the name tie-break comparator to keep case handling consistent.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant